﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Objects;
using System.Linq;
using System.Text;
using Infrastructure;

namespace Domain
{
    public partial class PfizerDBEntities
    {
        public void PersitentObject(object sender, EventArgs e)
        {
            PfizerDBEntities context = sender as PfizerDBEntities;
            IEnumerable<ObjectStateEntry> newObjectEntries = context.ObjectStateManager.GetObjectStateEntries(EntityState.Added);
            foreach (ObjectStateEntry oe in newObjectEntries)
            {
                if (!oe.IsRelationship)
                {
                    Reflector.Instance().SetValue(oe.Entity, "ID", Guid.NewGuid());
                    Reflector.Instance().SetValue(oe.Entity, "RecordStatus", 0);
                    Reflector.Instance().SetValue(oe.Entity, "CreatedOn", DateTime.Now);
                }
            }
 
        }

        partial void OnContextCreated()
        {
            this.SavingChanges += new EventHandler(PersitentObject);
        }

    }
}
